Skip to content

Add deterministic redistribute sharding for KafkaIO read. - #36112

Merged
chamikaramj merged 19 commits into
apache:masterfrom
tomstepp:kafka-key
Sep 30, 2025
Merged

Add deterministic redistribute sharding for KafkaIO read.#36112
chamikaramj merged 19 commits into
apache:masterfrom
tomstepp:kafka-key

Conversation

@tomstepp

Copy link
Copy Markdown
Contributor

Add deterministic redistribute sharding for KafkaIO read.


GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @tomstepp, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the data redistribution mechanism within Apache Beam by introducing a deterministic sharding option. This feature is specifically integrated into the KafkaIO connector to provide predictable data distribution, which is crucial for scenarios requiring consistent processing, such as offset deduplication.

Highlights

  • Introduction of Deterministic Sharding: A new "deterministicSharding" option has been added to the RedistributeArbitrarily transform, allowing elements to be sharded based on their hash code rather than a random assignment.
  • KafkaIO Integration: The KafkaIO.Read transform now leverages this new deterministic sharding capability when offset deduplication is enabled, ensuring consistent distribution of Kafka records.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Comment thread sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/Redistribute.java Outdated
@tomstepp

Copy link
Copy Markdown
Contributor Author

R: @scwhittle

@github-actions

Copy link
Copy Markdown
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment assign set of reviewers

Comment thread sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/Redistribute.java Outdated
Comment thread sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/Redistribute.java Outdated
@tomstepp
tomstepp requested a review from scwhittle September 11, 2025 16:22
@tomstepp

tomstepp commented Sep 12, 2025

Copy link
Copy Markdown
Contributor Author

Looks like the failures are unrelated and flaky tests (JmsIO and BeamFnLoggingClient)

Comment thread sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/Redistribute.java Outdated
Comment thread sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/Redistribute.java Outdated
Comment thread sdks/java/io/kafka/src/main/java/org/apache/beam/sdk/io/kafka/KafkaIO.java Outdated
Comment thread sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/Redistribute.java Outdated
Comment thread sdks/java/io/kafka/src/main/java/org/apache/beam/sdk/io/kafka/KafkaIO.java Outdated
Comment thread sdks/java/io/kafka/src/main/java/org/apache/beam/sdk/io/kafka/KafkaIO.java Outdated
@tomstepp

Copy link
Copy Markdown
Contributor Author

I don't understand why PreCommits are failing now since they pass locally and the lines mentioned in errors don't line up with the current KafkaIOTest file.

@liferoad

Copy link
Copy Markdown
Contributor

https://develocity.apache.org/s/kpt4uubaoc7b4

Compilation failed; see the compiler output below.
/runner/_work/beam/beam/sdks/java/io/kafka/src/test/java/org/apache/beam/sdk/io/kafka/KafkaIOTest.java:827: error: no suitable method found for mkKafkaReadTransform(int,int,ValueAsTimestampFn,boolean,boolean,<null>,<null>,<null>)
        mkKafkaReadTransform(
        ^
    method KafkaIOTest.mkKafkaReadTransform(int,@org.checkerframework.checker.nullness.qual.Nullable SerializableFunction<KV<Integer,Long>,Instant>) is not applicable
      (actual and formal argument lists differ in length)
    method KafkaIOTest.mkKafkaReadTransform(int,@org.checkerframework.checker.nullness.qual.Nullable Integer,@org.chec

@tomstepp

Copy link
Copy Markdown
Contributor Author

https://develocity.apache.org/s/kpt4uubaoc7b4

Compilation failed; see the compiler output below.
/runner/_work/beam/beam/sdks/java/io/kafka/src/test/java/org/apache/beam/sdk/io/kafka/KafkaIOTest.java:827: error: no suitable method found for mkKafkaReadTransform(int,int,ValueAsTimestampFn,boolean,boolean,<null>,<null>,<null>)
        mkKafkaReadTransform(
        ^
    method KafkaIOTest.mkKafkaReadTransform(int,@org.checkerframework.checker.nullness.qual.Nullable SerializableFunction<KV<Integer,Long>,Instant>) is not applicable
      (actual and formal argument lists differ in length)
    method KafkaIOTest.mkKafkaReadTransform(int,@org.checkerframework.checker.nullness.qual.Nullable Integer,@org.chec

However I don't see mkKafkaReadTransform at KafkaIOTest.java:827 (which is a blank line currently)

@liferoad

Copy link
Copy Markdown
Contributor

try to change null /*topics*/, to null, /*topics*/

@tomstepp

Copy link
Copy Markdown
Contributor Author

try to change null /*topics*/, to null, /*topics*/

Fixed this but the error message still exists and doesn't really make sense to me, not sure what I'm missing.

@liferoad

Copy link
Copy Markdown
Contributor

./gradlew :sdks:java:io:kafka:compileTestJava: this runs fine with your PR. Not sure what's going on.

@tomstepp

tomstepp commented Sep 23, 2025

Copy link
Copy Markdown
Contributor Author

./gradlew :sdks:java:io:kafka:compileTestJava: this runs fine with your PR. Not sure what's going on.

@liferoad, I realized that the line mismatches were probably due to pulling master into the branch for testing. After pulling master, resolving conflicts, and pushing, it looks like this is resolved now. Thanks for your help!

The latest errors I think are flakes or unrelated to this change.

@codecov

codecov Bot commented Sep 24, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.79%. Comparing base (0384a59) to head (06469c5).
⚠️ Report is 25 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #36112      +/-   ##
============================================
+ Coverage     54.92%   56.79%   +1.86%     
- Complexity     1617     3386    +1769     
============================================
  Files          1057     1220     +163     
  Lines        164391   185653   +21262     
  Branches       1165     3523    +2358     
============================================
+ Hits          90289   105435   +15146     
- Misses        71953    76884    +4931     
- Partials       2149     3334    +1185     
Flag Coverage Δ
java 70.39% <ø> (+2.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@scwhittle scwhittle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor comments. I'm not super familiar with the translation stuff, it might be a good idea to have someone else review for that.

@tomstepp

Copy link
Copy Markdown
Contributor Author

R: @chamikaramj

@tomstepp

Copy link
Copy Markdown
Contributor Author

Just some minor comments. I'm not super familiar with the translation stuff, it might be a good idea to have someone else review for that.

Thanks! Added Cham for translation.

@tomstepp

Copy link
Copy Markdown
Contributor Author

@chamikaramj could you please review?

@tomstepp
tomstepp requested a review from scwhittle September 30, 2025 17:09
@tomstepp

Copy link
Copy Markdown
Contributor Author

I think the non-translation LG to Sam and translation LG to Cham, so should be ready to merge by either.

@chamikaramj

Copy link
Copy Markdown
Contributor

Thanks. Re-ran the failing tests.

@chamikaramj
chamikaramj merged commit 4d87e04 into apache:master Sep 30, 2025
23 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants